/**
 * Created by mac on 2017/5/4.
 */

import java.io.*;
import java.security.NoSuchAlgorithmException;
import javax.crypto.*;

public class Skey_DES {
    public static void main(String args[])
            throws Exception {
        KeyGenerator kg = getDeSede();
        kg.init(168);
        SecretKey k = kg.generateKey();
        FileOutputStream f = getFileOutputStream();
        ObjectOutputStream b = getObjectOutputStream(f);
        b.writeObject(k);
    }

    private static ObjectOutputStream getObjectOutputStream(FileOutputStream f) throws IOException {
        return new ObjectOutputStream(f);
    }

    private static FileOutputStream getFileOutputStream() throws FileNotFoundException {
        return new FileOutputStream("key1.dat");
    }

    private static KeyGenerator getDeSede() throws NoSuchAlgorithmException {
        return KeyGenerator.getInstance("DESede");
    }
}
